﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using QL_DTTN.DAL;
namespace QL_DTTN.DTO.DTO
{
    public partial class Truong
    {
        public  Truong GetTruong(string maTruong)
        {
            bool kt = false;
            string sql = " select MaTruong,TenTruong,DiaChi from " + _tableName + " where MaTruong=@pMaTruong ";
            SqlDataProvider dp = new SqlDataProvider();
            dp.AddParameter(new SqlParameter("@pMaTruong", maTruong));
            System.Data.SqlClient.SqlDataReader sqlRr = dp.ExDataReader(sql, true);
            Truong dt = new Truong();
            if (sqlRr != null)
            {
                while (sqlRr.Read())
                {
                    if (!Convert.IsDBNull(sqlRr["MaTruong"])) dt.MaTruong = sqlRr["MaTruong"].ToString();
                    if (!Convert.IsDBNull(sqlRr["TenTruong"])) dt.TenTruong = sqlRr["TenTruong"].ToString();
                    if (!Convert.IsDBNull(sqlRr["DiaChi"])) dt.DiaChi = sqlRr["DiaChi"].ToString();
                    kt = true;
                }
                dp.CloseConnection();
                if (kt) return dt;
                else return null;
            }
            else
            {
                return null;
            }
        }
    }
}
